home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / NETLIST / NITABLE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-23  |  3.7 KB  |  120 lines

  1. // the implementation of class NET_ITEM_TABLE
  2. // Copyright (C) 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  3.  
  4. #include "nilist.h"
  5. #include "segpoint.h"
  6. #include "segseg.h"
  7.  
  8. #include "nitable.h"
  9.  
  10. void NET_ITEM_TABLE::AddItem(KBAN_DATA& kban_data)
  11. {
  12.   NET_ITEM_LIST net_item_list;
  13.   net_item_list.collect_kban_data(kban_data);
  14.  
  15.   NET_ITEM_LIST::iterator i;
  16.   reserve(net_item_list.size());
  17.   for(i = net_item_list.begin(); i != net_item_list.end(); i++) {
  18.     push_back(*i);
  19.   }
  20. }
  21.  
  22. XY_DBL xy_int2dbl(const XY& xy)
  23. {
  24.   return XY_DBL(xy.x(), xy.y());
  25. }
  26.  
  27. bool is_connected_pin_pin(
  28.   const PIN_ELEMENT& pin1,
  29.   const PIN_ELEMENT& pin2
  30. )
  31. {
  32.   XY_DBL ac1 = xy_int2dbl(pin1.ac());
  33.   XY_DBL ac2 = xy_int2dbl(pin2.ac());
  34.   uint threshold = pin1.GetMinimumRadius() + pin2.GetMinimumRadius();
  35.   return (get_distance(ac1, ac2) < threshold) ? true : false;
  36. }
  37.  
  38. bool is_connected_pin_line(
  39.   const PIN_ELEMENT&  pin,
  40.   const LINE_ELEMENT& line
  41. )
  42. {
  43.   XY_DBL ac_o = xy_int2dbl(pin.ac());
  44.   XY_DBL ac_s = xy_int2dbl(line.ac_s());
  45.   XY_DBL ac_e = xy_int2dbl(line.ac_e());
  46.   SEGMENT seg(ac_s - ac_o, ac_e - ac_o);
  47.   uint threshold = pin.GetMinimumRadius() + line.GetMinimumRadius();
  48.   return (GetDistanceFromOrigin(seg) < threshold) ? true : false;
  49. }
  50.  
  51. bool is_connected_line_line(
  52.   const LINE_ELEMENT& line1,
  53.   const LINE_ELEMENT& line2
  54. )
  55. {
  56.   XY_DBL ac1_s = xy_int2dbl(line1.ac_s());
  57.   XY_DBL ac1_e = xy_int2dbl(line1.ac_e());
  58.   XY_DBL ac2_s = xy_int2dbl(line2.ac_s());
  59.   XY_DBL ac2_e = xy_int2dbl(line2.ac_e());
  60.   SEGMENT seg1(ac1_s, ac1_e);
  61.   SEGMENT seg2(ac2_s, ac2_e);
  62.   uint threshold = line1.GetMinimumRadius() + line2.GetMinimumRadius();
  63.   return (segseg(seg1, seg2) < threshold) ? true : false;
  64. }
  65.  
  66. bool is_connected_item_item(const NET_ITEM& item1, const NET_ITEM& item2)
  67. {
  68.   bool result = false;
  69.   if((item1.type() == NET_ITEM::ITEM_PIN) && (item2.type() == NET_ITEM::ITEM_PIN)) {
  70.     const PIN_ELEMENT& pin_element1 = item1.get_pin_element();
  71.     const PIN_ELEMENT& pin_element2 = item2.get_pin_element();
  72.     if(is_connected_pin_pin(pin_element1, pin_element2)) {
  73.       result = true;
  74.     }
  75.   } else if((item1.type() == NET_ITEM::ITEM_PIN) && (item2.type() == NET_ITEM::ITEM_LINE)) {
  76.     const PIN_ELEMENT&  pin_element  = item1.get_pin_element();
  77.     const LINE_ELEMENT& line_element = item2.get_line_element();
  78.     if(is_connected_pin_line(pin_element, line_element)) {
  79.       result = true;
  80.     }
  81.   } else if((item1.type() == NET_ITEM::ITEM_LINE) && (item2.type() == NET_ITEM::ITEM_PIN)) {
  82.     const LINE_ELEMENT& line_element = item1.get_line_element();
  83.     const PIN_ELEMENT&  pin_element  = item2.get_pin_element();
  84.     if(is_connected_pin_line(pin_element, line_element)) {
  85.       result = true;
  86.     }
  87.   } else if((item1.type() == NET_ITEM::ITEM_LINE) && (item2.type() == NET_ITEM::ITEM_LINE)) {
  88.     const LINE_ELEMENT& line_element1 = item1.get_line_element();
  89.     const LINE_ELEMENT& line_element2 = item2.get_line_element();
  90.     if(is_connected_line_line(line_element1, line_element2)) {
  91.       result = true;
  92.     }
  93.   }
  94.   return result;
  95. }
  96.  
  97. void NET_ITEM_TABLE::GenerateNetlist(uint layer_number)
  98. {
  99.   for(uint i = 0; i < size(); i++) {
  100.     NET_ITEM& item1 = (*this)[i];
  101.     if((item1.layer_number() != LAYER_PATTERN_COMMON)
  102.     && (item1.layer_number() != layer_number        )) {
  103.       continue;
  104.     }
  105.     for(uint j = i + 1; j < size(); j++) {
  106.       if(IsConnected(i, j)) {
  107.         continue;
  108.       }
  109.       NET_ITEM& item2 = (*this)[j];
  110.       if((item2.layer_number() != LAYER_PATTERN_COMMON)
  111.       && (item2.layer_number() != layer_number        )) {
  112.         continue;
  113.       }
  114.       if(is_connected_item_item(item1, item2)) {
  115.         MakeConnection(i, j);
  116.       }
  117.     }
  118.   }
  119. }
  120.